﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HANS_Base.Model
{
    public  class FileUploadModel
    {
        /// <summary>
        /// 语言
        /// </summary>
        public string language { get; set; } = "zh";

        /// <summary>
        /// 显示正确的文件标题
        /// </summary>
        public bool overwriteInitial { get; set; } = true;

        /// <summary>
        /// 是否显示被选文件的简介
        /// </summary>
        public bool showCaption { get; set; } = true;

        /// <summary>
        /// 是否显示浏览按钮
        /// </summary>
        public bool showBrowse { get; set; } = true;

        /// <summary>
        /// 是否显示预览区域
        /// </summary>
        public bool showPreview { get; set; } = true;
        /// <summary>
        /// 是否显示移除按钮
        /// </summary>
        public bool showRemove { get; set; } = true;

        /// <summary>
        /// 是否显示上传按钮
        /// </summary>
        public bool showUpload { get; set; } = true;

        /// <summary>
        /// 是否显示取消按钮
        /// </summary>
        public bool showCancel { get; set; } = true;

        /// <summary>
        /// 是否显示关闭按钮
        /// </summary>
        public bool showClose { get; set; } = true;


        /// <summary>
        /// 展示图片区域是否可点击选择多文件
        /// </summary>
        public bool browseOnZoneClick { get; set; } = false;
        /// <summary>
        /// 是否自动替换当前图片，设置为true时，再次选择文件， 会将当前的文件替换掉。
        /// </summary>
        public bool autoReplace { get; set; } = false;

        /// <summary>
        /// 接收的文件后缀，如['jpg', 'gif', 'png'],不填将不限制上传文件后缀类型
        /// </summary>
        public string[] allowedFileTypes { get; set; } = new string[] { "image" };
        /// <summary>
        /// 允许文件正则表达式
        /// </summary>
        public object allowedFileExtensions { get; set; } = null;

        /// <summary>
        /// 默认预览object
        /// </summary>
        public object defaultPreviewContent { get; set; } = null;

        /// <summary>
        /// 上传路径
        /// </summary>
        public string uploadUrl { get; set; } = null;

        /// <summary>
        /// 是否为异步上传
        /// </summary>
        public bool uploadAsync { get; set; } = false;

        /// <summary>
        /// 上传文件时额外传递的参数设置
        /// </summary>
        public object uploadExtraData { get; set; } = null;

        /// <summary>
        /// 图片的最小宽度
        /// </summary>
        public string minImageWidth { get; set; } = null;
        /// <summary>
        /// 图片的最小高度
        /// </summary>
        public string minImageHeight { get; set; } = null;

        /// <summary>
        /// 图片的最大宽度
        /// </summary>
        public string maxImageWidth { get; set; } = null;
        /// <summary>
        /// 图片的最大高度
        /// </summary>
        public string maxImageHeight { get; set; } = null;
        /// <summary>
        /// 单位为kb，上传文件的最小大小值 
        /// </summary>
        public int minFileSize { get; set; } = 0;
        /// <summary>
        /// 单位为kb，如果为0表示不限制文件大小
        /// </summary>
        public int maxFileSize { get; set; } = 0;
        /// <summary>
        /// 表示同时最小上传的文件个数
        /// </summary>
        public int minFileCount { get; set; } = 0;
        /// <summary>
        /// 表示允许同时上传的最大文件个数
        /// </summary>
        public int maxFileCount { get; set; } = 0;
        /// <summary>
        /// 预览文件类型,内置['image', 'html', 'text', 'video', 'audio', 'flash', 'object',‘other‘]等格式
        /// </summary>
        public string[] previewFileType = new string[] { "image" };

        /// <summary>
        /// 是否显示拖拽区域
        /// </summary>
        public bool dropZoneEnabled { get; set; } = false;

        /// <summary>
        /// textEncoding
        /// </summary>
        public string textEncoding { get; set; } = "UTF-8";


        public List<JQueryFileInputPreviewModel> Previews { private get; set; } = new List<JQueryFileInputPreviewModel>();

        public List<string> initialPreview
        {
            get
            {
                return Previews.Select(p =>
                $"'<a href=\"{p.Url}\"><img src=\"{p.Src}\" class=\"file-preview-image\" alt=\"\" title=\"\"></a>'").ToList();
            }
        }

        public List<JQueryFileInputPreviewConfigModel> initialPreviewConfig { get; set; }
    }

    public class JQueryFileInputPreviewModel
    {
        public string Url { get; set; } = "javascript:void(0);";
        public string Src { get; set; }
    }


    public class JQueryFileInputPreviewConfigModel
    {
        public string width { get; set; } = "160px";
        public string url { get; set; }
        public object extra { get; set; }
    }
}

